<?php

class Core_Action_Admin_Appearance_Menu_Edit extends Action_Admin
{
	function execute($request, $initial = FALSE)
	{
		if ($initial)
		{
			Agilet::setVar('breadcrum', array(
				array(
					'url' => 'admin/appearance',
					'label' => 'Appearance'
				),
				array(
					'url' => 'admin/appearance/menu',
					'label' => 'Menu'
				),
				array(
					'url' => 'admin/appearance/menu/edit',
					'label' => 'Edit'
				)
			));

		}

		$form = Form::factory('core/admin/menu/edit');

		$id = $request -> getParam('id');

		$table = Model::getTable('core/menu');

		$item = $table -> find($id) -> current();

		if ($request -> isGet() && $id)
		{
			$form -> setData($item -> toArray());
		}

		if ($request -> isPost() && $form -> isValid($_POST))
		{
			$data = $form -> getData();

			$item -> title = $data['title'];

			$item -> css_class = $data['css_class'];

			$item -> css_id = $data['css_id'];

			$item -> clearfix = $data['clearfix'];

			$item -> save();

			$form -> setNotice('Saved');
		}

		$request -> response = View::render($script = 'core/html/admin/appearance/menu/edit', $data = array('form' => $form));
	}

}
